<?php

namespace Tests\Feature\Admin;

use App\Enum\Http\ApiCode;
use Illuminate\Testing\Fluent\AssertableJson;
use Illuminate\Testing\TestResponse;
use Tests\TestCase;

class AdminBaseControllerCase extends TestCase
{
    /**
     * 断言成功响应状态
     */
    public function assertApiSuccessTest(TestResponse $response): void
    {
        $this->assertApiTest($response, ApiCode::Success);
    }

    /**
     * 断言失败响应
     */
    public function assertApiErrorTest(TestResponse $response): void
    {
        $this->assertApiTest($response, ApiCode::Error);
    }

    /**
     * 断言验证失败响应
     */
    public function assertApiValidateErrorTest(TestResponse $response): void
    {
        $this->assertApiTest($response, ApiCode::ValidateError);
    }

    public function assertApiTest(TestResponse $response, ApiCode $code)
    {
        $response->assertStatus(200);

        $response->assertJson(fn (AssertableJson $json) => $json->where('code', $code->value)
            ->etc()
        );
    }
}
